package top.javahai.subtlechat.base.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import top.javahai.subtlechat.api.pojo.User;
import top.javahai.subtlechat.base.dao.ChatUserDao;
import top.javahai.subtlechat.base.service.ChatUserService;

/**
 * @author qiangfanghao
 * @date
 */
@Service("chatUser")
public class ChatUserServiceImpl implements ChatUserService, UserDetailsService {

    @Autowired
    private ChatUserDao chatUserDao;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (StringUtils.isEmpty(username)){
            throw new UsernameNotFoundException("用户名称不能为空!");
        }
        User user = chatUserDao.loadUserByUsername(username);
        if (user==null){
            throw new UsernameNotFoundException("用户不存在");
        }
        return user;
    }
}
